#
#    Copyright 2007-2010 Adobe Systems Incorporated
#    Copyright 2018-2019 Chris Cox
#    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
#     or a copy at http://stlab.adobe.com/licenses.html )
#

###################################################
#
# Makefile for C++ benchmarks
#
###################################################


#
# Macros
#

INCLUDE = -I.


# GCC (defaults to Clang/LLVM on MacOS)
#CC = gcc
#CXX = g++


# GCC 8
#CC = gcc-8
#CXX = g++-8


# Clang/LLVM 8
#CC = clang-8
#CXX = clang++-8

CFLAGS = $(INCLUDE) $(OPTLEVEL) 
CPPFLAGS = -std=c++14 $(INCLUDE) $(OPTLEVEL) 

CLIBS = -lm
CPPLIBS = -lm

DEPENDENCYFLAG = -M

REPORT_FILE = report.txt

#
# our target programs
#

BINARIES = machine \
loop_unroll \
simple_types_loop_invariant \
simple_types_constant_folding \
scalar_replacement_arrays \
scalar_replacement_structs \
shift \
divide \
loop_normalize \
random_numbers \
lookup_table \
loop_induction \
loop_removal \
loop_fusion \
simple_types_algebraic_simplification \
loop_interchange \
memcpy \
binary_search \
loop_unswitching 




#
# Build rules
#

all : $(BINARIES)


SUFFIXES:
.SUFFIXES: .c .cpp


# declare some targets to be fakes without real dependencies

.PHONY : clean dependencies

# remove all the stuff we build

clean : 
		rm -f *.o $(BINARIES) $(REPORT_FILE)


# generate dependency listing from all the source files
# used for double checking problems with headers
# this does NOT go in the makefile

SOURCES = $(wildcard *.c)  $(wildcard *.cpp)
dependencies :   $(SOURCES)
	$(CXX) $(DEPENDENCYFLAG) $(CPPFLAGS) $^

#
# Run the benchmarks and generate a report
#

report:  $(BINARIES)
	echo "##STARTING Version 1.0" > $(REPORT_FILE)
	date >> $(REPORT_FILE)
	echo "##Compiler: $(CC) $(CXX)" >> $(REPORT_FILE)
	echo "##CFlags: $(CFLAGS)" >> $(REPORT_FILE)
	echo "##CPPFlags: $(CPPFLAGS)" >> $(REPORT_FILE)
	echo "System Information collected by program: " >> $(REPORT_FILE)
	./machine >> $(REPORT_FILE)
	./loop_unroll >> $(REPORT_FILE)
	./simple_types_loop_invariant >> $(REPORT_FILE)
	./simple_types_constant_folding >> $(REPORT_FILE)
	./scalar_replacement_arrays >> $(REPORT_FILE)
	./scalar_replacement_structs  >> $(REPORT_FILE)
	./shift >> $(REPORT_FILE)
	./divide >> $(REPORT_FILE)
	./loop_normalize >> $(REPORT_FILE)
	./random_numbers >> $(REPORT_FILE)
	./lookup_table >> $(REPORT_FILE)
	./loop_induction >> $(REPORT_FILE)
	./loop_removal >> $(REPORT_FILE)
	./loop_fusion >> $(REPORT_FILE)
	./simple_types_algebraic_simplification >> $(REPORT_FILE)
	./loop_interchange  >> $(REPORT_FILE)
	./memcpy >> $(REPORT_FILE)
	./binary_search >> $(REPORT_FILE)
	./loop_unswitching >> $(REPORT_FILE)
	date >> $(REPORT_FILE)
	echo "##END Version 1.0" >> $(REPORT_FILE)

